﻿using System.Data.SQLite;
using System.Data;

namespace hw11
{
    internal class SqliteUtil
    {    
        // 读取数据库并返回一个DataTable
        public static Dictionary<string, string> getWords(string sql, string conStr)
        {
            Dictionary<string, string> words = new Dictionary<string, string>();
            string ch;
            string en;
            using(SQLiteConnection conn = new SQLiteConnection(conStr))
            {
                SQLiteCommand command = new SQLiteCommand("select * from word", conn);
                conn.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ch = reader["ch_word"].ToString();
                        en = reader["en_word"].ToString();
                        words.Add(ch, en);
                    }
                }
                reader.Close();
                conn.Close();                
            }
            return words;
        }
    }
}
